package GUI.TabPanels;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import GUI.Controller.Controller;

@SuppressWarnings("serial")
public class AddFeesPanel extends JPanel {
	private JLabel description_label = new JLabel("Description");
	private JTextField description_text = new JTextField(9);

	private JLabel cost_label = new JLabel("Cost:");
	private JTextField cost_text = new JTextField(9);
	
	private JLabel booking_label = new JLabel("Booking:");
	private JComboBox booking_list;
	
	private String[][] booking_table;

	private JButton add_cost;

	public AddFeesPanel(){
		this.setLayout(new BorderLayout());

		JPanel west = new JPanel();
		JPanel center = new JPanel();
		JPanel east = new JPanel();

		west.setBackground(new Color(147, 37, 37));
		west.add(new JLabel("      "));
		east.setBackground(new Color(147, 37, 37));
		east.add(new JLabel("      "));

		center.setLayout(new GridLayout(0, 2));
	 
		add_cost = new JButton("Add Cost");
		add_cost.addActionListener(new AddCostButton());

		center.add(description_label);
		center.add(description_text);
		center.add(cost_label);
		center.add(cost_text);
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		center.add(new JLabel("     "));
		
		booking_table =Controller.GetBookings(null, "CHECKED_IN");
		String[] booking_array = new String[booking_table.length];
		for(int i = 0; i<booking_table.length; i++){
			booking_array[i] = "Booking ID: " + booking_table[i][0] +", Name: "+ booking_table[i][1] +
					" "+booking_table[i][2] +", Room Number: "+ booking_table[i][4];
		}
		booking_list = new JComboBox(booking_array);
		center.add(booking_label);
		center.add(booking_list);
		JPanel buttons = new JPanel();
		buttons.add(add_cost);

		center.add(buttons);

		this.add(west, BorderLayout.WEST);
		this.add(center, BorderLayout.CENTER);
		this.add(east, BorderLayout.EAST);
	}
	
	private class AddCostButton implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			Controller.AddCost(booking_table[booking_list.getSelectedIndex()][0], cost_text.getText(), description_text.getText());
		}
	}
}
